//
// Created by Administrator on 2021/11/13.
// May Saint Diana bless you!
//
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

class Solution {
public:
    vector<int> temp;
    vector<vector<int>> ans;

    void dfs(int cur, int last, vector<int> &nums) {
        if (cur == nums.size()) {
            if (temp.size() >= 2) {
                ans.push_back(temp);
            }
            return;
        }
        //  序列合法
        if (nums[cur] >= last) {
            temp.push_back(nums[cur]);
            dfs(cur + 1, nums[cur], nums); // 选择这个数
            temp.pop_back();
        }
        // 只有当当前的元素不等于上一个选择的元素的时候，才考虑不选择当前元素，直接递归后面的元素
        if (nums[cur] != last) {
            dfs(cur + 1, last, nums); // 不选择这个数
        }
    }

    vector<vector<int>> findSubsequences(vector<int> &nums) {
        dfs(0, INT_MIN, nums); // 初始last选择INT_MIN,保证都能进入
        return ans;
    }
};


int main() {
    vector<int> nums{4, 6, 1, 7};
    Solution solution;
    auto ans = solution.findSubsequences(nums);
    for (const auto &row:ans) {
        for (const auto &x:row) {
            cout << x << " ";
        }
        cout << endl;
    }
    return 0;
}


